//扩展jquery方法
(function($){
$.getUrlParam
 = function(name)
{
var reg
 = new RegExp("(^|&)"+
 name +"=([^&]*)(&|$)");
var r
 = window.location.search.substr(1).match(reg);
if (r!=null) return unescape(r[2]); return null;
}
})(jQuery);
//获取参数
window.page = $.getUrlParam('page');
if(window.page==null || window.page==""){
    window.page = 1;
}
window.onload = function(){
    //加载表格中用户捐赠数据
    $.post('?c=Donate&a=getDonateBookList&page='+window.page,{},function(result){
        var res = JSON.parse(result);
        var arr = res.res_arr;
        if(arr.length!=0){
            //有记录
            //循环遍历arr数组，并且append
            for(i=0;i<arr.length;i++){
                status = "";
                //<span class='badge badge-warning'>待支付</span>
                //<span class="badge badge-success">已支付</span>
                //<span class="badge badge-muted">异常</span>
                if(arr[i].status==0){
                    status = "<span class='badge badge-warning'>待收书</span>";
                }else if(arr[i].status==1){
                    status = "<span class='badge badge-success'>已收书</span>";
                }else if(arr[i].status==2){
                    status = "<span class='badge badge-info'>已入库</span>";
                }else{
                    status = "<span class='badge badge-muted'>异常</span>";
                }
                var con = "<tr><td>"+arr[i].donate_book_id+"</td><td>"+arr[i].donate_book_time+"</td><td>"+status+"</td><td><button class='btn btn-primary .btn-round' id='detail'>明细</button></td></tr>";
                $("#tbody").append(con);
                //<div class='btn-group'><a class='btn btn-xs btn-default'  title='明细查看' id='detail' donate-id='"+arr[i].donate_book_id+"' data-toggle='tooltip' data-original-title='明细查看'><i class='mdi mdi-android-messages'></i></a></div>
            }
        }else{
            //如果没有记录
            $("#tbody").append("没有数据了");
        }
            //填入页码
            //console.log(res);
            var shouye = "";
            var weiye = "";
            res.page = parseInt(res.page);
            //首页样式判断
            if(res.page>1){
                shouye = "<a class='page-link' href='?c=User&a=donateBookList&page=1' tabindex='-1'>首页</a>";
            }else{
                shouye = "<li class='page-item disabled'><span class='page-link'>首页</span></li>";
            }
            $("#page").append(shouye);
            //尾页样式判断
            if(res.page<res.end){
                weiye = "<a class='page-link' href='?c=User&a=donateBookList&page='"+res.pages+" >尾页</a>";
            }else if(res.page==res.end){
                weiye = "<li class='page-item disabled'><span class='page-link'>尾页</span></li>";
            }
            
            //循环输出中间页码
            for(var i=res.start;i<=res.end;i++){
                if(res.page==i){
                    $("#page").append("<li class='page-item active'><span class='page-link'>"+i+"</span></li>");
                }else{
                    $("#page").append("<li class='page-item'><a class='page-link' href='?c=User&a=donateBookList&page="+i+"'>"+i+"</a></li>");
                }
            }
            //尾
            $("#page").append(weiye);
    });

}


